﻿using System;
using System.Collections;

namespace Microsoft.WPF.Samples
{
    /// <summary>
    /// The BizCardFlowPage is used as hosting container for MFC apps.
    /// </summary>
    public partial class BizCardFlowPage
    {
        // Events

        #region SelectedItemChanged
        private event EventHandler _selectedItemChanged;

        private static readonly object _selectedItemChangedLock =
            new object();

        /// <summary>
        /// Occurs when the selected item changes.
        /// </summary>
        public event EventHandler SelectedItemChanged
        {
            add { lock (_selectedItemChangedLock) _selectedItemChanged += value; }
            remove { lock (_selectedItemChangedLock) _selectedItemChanged -= value; }
        }

        private void OnCoverFlowListSelectedItemChanged(object sender, EventArgs e)
        {
            if (_selectedItemChanged != null) _selectedItemChanged(sender, e);
        }
        #endregion


        // Constructor

        #region BizCardFlowPage()
        /// <summary>
        /// Initializes a new instance of the 
        /// <see cref="BizCardFlowPage"/> class.
        /// </summary>
        public BizCardFlowPage()
        {
            InitializeComponent();
            BizCardFlow1.SelectedItemChanged +=
                OnCoverFlowListSelectedItemChanged;
        } 
        #endregion


        // Properties

        #region ItemsSource
        /// <summary>
        /// Gets or sets the item source.
        /// </summary>
        /// <value>The item source.</value>
        public IEnumerable ItemsSource
        {
            get { return BizCardFlow1.ItemsSource; }
            set
            {
                BizCardFlow1.ItemsSource = value;
                OnCoverFlowListSelectedItemChanged(this, EventArgs.Empty);
            }
        }
        
        #endregion

        #region SelectedItem
        /// <summary>
        /// Gets the selected item.
        /// </summary>
        /// <value>The selected item.</value>
        public object SelectedItem
        {
            get { return BizCardFlow1.SelectedItem; }
        } 
        #endregion

        #region SelectedIndex
        /// <summary>
        /// Gets or sets the index of the selected.
        /// </summary>
        /// <value>The index of the selected.</value>
        public int SelectedIndex
        {
            get { return BizCardFlow1.SelectedIndex; }
            set
            {
                BizCardFlow1.SelectedIndex = value;
            }
        }
        #endregion
    }
}
